import { genPinYinCode,genFirstPinYinCode } from "@/util/util";

// 检查打印数量
export function checkPrintNumber(that) {
  var flag = true;
  for (let i = 0; i < that.dataList.length; i++) {
    if (isNaN(that.dataList[i].quantity) || that.dataList[i].quantity <= 0) {
      alert('请填写正确的打印数量')
      flag = false
      that.$refs['quantity' + i].focus()
      return flag
    }
  }
  return flag
}

// 检查品种价格
export function checkPrintPrices(that){
  var reg_price = /^([1-9]{1,1}\d{0,10})\.\d{2,2}--([1-9]{1,1}\d{0,10})\.\d{2,2}$/;
  var flag = true;
  for(let i = 0; i < that.dataList.length; i++){
    if(reg_price.exec(that.dataList[i].retailprice) == null){
      alert("零售价范围格式不正确!正确格式为: 12.00--45.00");
      that.$refs['retailprice' + i].focus()
      flag = false;
      return flag
    }else{
      var prices = that.dataList[i].retailprice.split("--");
      if(parseFloat(prices[0]) > parseFloat(prices[1])) {
          alert("价格顺序填写有误!请按从小到大的顺序填写!");
          that.$refs['retailprice' + i].focus()
          flag = false;
          return flag
      }
    }
  }
  return flag;
}

// 条码打印
export function PrintBarcode(that) {
  let barCode = new Array();
  let quantity = new Array();
  let brandname = new Array();
  let spec = new Array();
  let color = new Array();
  let retailprice = new Array();
  let person = new Array();
  let guaranteeperiod = new Array();
  let batch = new Array();
  for (let i = 0; i < that.dataList.length; i++) {
    person[person.length] = that.userInfo.username
    barCode[barCode.length] = that.dataList[i].goodsBarcode
    quantity[quantity.length] = that.dataList[i].quantity
    spec[spec.length] = that.dataList[i].spec
    color[color.length] = (that.dataList[i].color) ? that.dataList[i].color : ''
    retailprice[retailprice.length] = that.dataList[i].goodsPrice

    guaranteeperiod[batch.length] = (that.dataList[i].invalidTime) ? that.dataList[i].invalidTime : ''
    batch[batch.length] = (that.dataList[i].batch) ? that.dataList[i].batch : ''
    brandname[brandname.length] = that.dataList[i].brandName

  }
  var printtype = {
    "1": "3",
    "2": "2",
    "3": "5",
    "4": "4",
    "5": "4",
    "6": "3",
    "7": "4",
    "8": "3",
    "9": "4"
  };
  printBarCode(that, barCode, quantity, brandname, spec, color, retailprice, person, printtype, guaranteeperiod, batch);
}

// 条码打印
export function printBarCode(that, barCode, quantity, brandname, spec, color, retailprice, person, printtype,
  guaranteeperiod,
  batch) {
  var barCodes = new Array();
  var brandnames = new Array();
  var specs = new Array();
  var colors = new Array();
  var retailprices = new Array();
  var persons = new Array();
  var guaranteeperiods = new Array();
  var batchs = new Array();
  for (var i = 0; i < barCode.length; i++) {
    for (var a = 0; a < quantity[i]; a++) {
      barCodes[barCodes.length] = barCode[i];
      brandnames[brandnames.length] = brandname[i];
      specs[specs.length] = spec[i];
      colors[colors.length] = color[i];
      retailprices[retailprices.length] = retailprice[i];
      persons[persons.length] = person[i];
      if (guaranteeperiod) {
        guaranteeperiods[guaranteeperiods.length] = guaranteeperiod[i];
      } else {
        guaranteeperiods[guaranteeperiods.length] = '';
      }
      if (batch) {
        batchs[batchs.length] = batch[i];
      } else {
        batchs[batchs.length] = '';
      }
    }
  }
  let content = ''
  if (/^[1]/.test(barCodes[0])) {
    content = callPrint1(that, barCodes, brandnames, specs, colors, retailprices, persons)
  } else if (/^[2]/.test(barCodes[0])) {
    content = callPrint2(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[3]/.test(barCodes[0])) {
    content = callPrint3(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[4]/.test(barCodes[0])) {
    content = callPrint4(that, barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs);
  } else if (/^[5]/.test(barCodes[0])) {
    content = callPrint5(that, barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs);
  } else if (/^[6]/.test(barCodes[0])) {
    content = callPrint6(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[7]/.test(barCodes[0])) {
    content = callPrint7(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[8]/.test(barCodes[0])) {
    content = callPrint8(that, barCodes, brandnames, specs, colors, retailprices, persons);
  } else if (/^[9]/.test(barCodes[0])) {
    content = callPrint9(that, barCodes, brandnames, specs, colors, retailprices, persons);
  }
  that.axios({
    method: 'POST',
    url: 'http://noble-print:11881/noble-print/print/printContent',
    data: {
      content: content
    }
  }).then(response => {
    console.log(response)
  }).catch(function(error) {
    console.log(error);
  });
}

export function callPrint1(that, barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print1(barCode, brandname, spec, color, retailprice, person);
}

export function Print1(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,50^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,230^A0N,20,20^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,260^A0N,20,20^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO770,50^AXB,32,25^FD" + "B:" + genFirstPinYinCode(printbrandname[i + 0]) + "^FS";
    printstr = printstr + "^FO810,50^AXB,32,25^FD" + "T:" + printspec[i + 0] + "^FS";
    var printctype = "C:";
    printstr = printstr + "^FO850,50^AXB,32,25^FD" + printctype + printcolor[i + 0] + "^FS";
    printstr = printstr + "^FO890,50^AXB,32,25^FD" + "P:" + printretailprice[i + 0] + "^FS";
    printstr = printstr + "^PQ1^FS";
    printstr = printstr + "^XZ";
    i = i + 0;
  }
  return printstr
}

export function callPrint2(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print2(barCode, brandname, spec, color, retailprice, person);
}

export function Print2(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,40^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,240^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^FO350,40^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO350,220^A0N,21,21^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO350,240^A0N,21,21^FD" + printbarCode[i + 1].substring(13) + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^FO600,40^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO600,220^A0N,21,21^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO600,240^A0N,21,21^FD" + printbarCode[i + 2].substring(13) + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

export function callPrint3(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print3(barCode, brandname, spec, color, retailprice, person);
}

export function Print3(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,30^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,240^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO100,20^A0N,21,21^FDq^FS";
    printstr = printstr + "^FO130,20^A0N,21,21^FDw^FS";
    printstr = printstr + "^FO160,20^A0N,21,21^FDe^FS";
    printstr = printstr + "^FO190,20^A0N,21,21^FDr^FS";
    printstr = printstr + "^FO220,20^A0N,21,21^FDt^FS";
    printstr = printstr + "^FO100,20^A0N,21,21^FDnull^FS";
    printstr = printstr + "^FO130,20^A0N,21,21^FDnull^FS";
    printstr = printstr + "^FO160,20^A0N,21,21^FDnull^FS";
    printstr = printstr + "^FO190,20^A0N,21,21^FDnull^FS";
    printstr = printstr + "^FO220,20^A0N,21,21^FDnull^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^FO350,30^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO350,220^A0N,21,21^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO350,240^A0N,21,21^FD" + printbarCode[i + 1].substring(13) + "^FS";
      printstr = printstr + "^FO350,20^A0N,21,21^FDq^FS";
      printstr = printstr + "^FO380,20^A0N,21,21^FDw^FS";
      printstr = printstr + "^FO410,20^A0N,21,21^FDe^FS";
      printstr = printstr + "^FO440,20^A0N,21,21^FDr^FS";
      printstr = printstr + "^FO470,20^A0N,21,21^FDt^FS";
      printstr = printstr + "^FO350,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO380,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO410,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO440,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO470,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^FO600,30^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO600,220^A0N,21,21^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO600,240^A0N,21,21^FD" + printbarCode[i + 2].substring(13) + "^FS";
      printstr = printstr + "^FO600,20^A0N,21,21^FDq^FS";
      printstr = printstr + "^FO630,20^A0N,21,21^FDw^FS";
      printstr = printstr + "^FO660,20^A0N,21,21^FDe^FS";
      printstr = printstr + "^FO690,20^A0N,21,21^FDr^FS";
      printstr = printstr + "^FO720,20^A0N,21,21^FDt^FS";
      printstr = printstr + "^FO600,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO630,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO660,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO690,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^FO720,20^A0N,21,21^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

export function callPrint4(barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  var guaranteeperiod = '';
  var batch = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
    guaranteeperiod = guaranteeperiod + guaranteeperiods[cStr] + '|';
    batch = batch + batchs[cStr] + '|';
  }
  return Print4(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch);
}

export function Print4(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var printguaranteeperiod = new Array();
  printguaranteeperiod = guaranteeperiod.split('|');
  var printbatch = new Array();
  printbatch = batch.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO120,20^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO120,180^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO120,200^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO120,220^A0N,19,19^FD" + "效期:" + printguaranteeperiod[i + 0] + "^FS";
    printstr = printstr + "^FO120,240^A0N,19,19^FD" + "批号:" + printbatch[i + 0] + "^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^FO370,20^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO370,180^A0N,21,21^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO370,200^A0N,21,21^FD" + printbarCode[i + 1].substring(13) + "^FS";
      printstr = printstr + "^FO370,220^A0N,19,19^FD" + "效期:" + printguaranteeperiod[i + 1] + "^FS";
      printstr = printstr + "^FO370,240^A0N,19,19^FD" + "批号:" + printbatch[i + 1] + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^FO620,20^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO620,180^A0N,21,21^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO620,200^A0N,21,21^FD" + printbarCode[i + 2].substring(13) + "^FS";
      printstr = printstr + "^FO620,220^A0N,19,19^FD" + "效期:" + printguaranteeperiod[i + 2] + "^FS";
      printstr = printstr + "^FO620,240^A0N,19,19^FD" + "批号:" + printbatch[i + 2] + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

export function callPrint5(barCodes, brandnames, specs, colors, retailprices, persons, guaranteeperiods, batchs) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  var guaranteeperiod = '';
  var batch = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
    guaranteeperiod = guaranteeperiod + guaranteeperiods[cStr] + '|';
    batch = batch + batchs[cStr] + '|';
  }
  return Print5(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch);
}

export function Print5(barCode, brandname, spec, color, retailprice, person, guaranteeperiod, batch) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var printguaranteeperiod = new Array();
  printguaranteeperiod = guaranteeperiod.split('|');
  var printbatch = new Array();
  printbatch = batch.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,40^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,240^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO100,30^AXN,21,21^FD^FS";
    printstr = printstr + "^FO100,30^AXN,21,21^FDnull^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^FO350,40^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO350,220^A0N,21,21^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO350,240^A0N,21,21^FD" + printbarCode[i + 1].substring(13) + "^FS";
      printstr = printstr + "^FO350,30^AXN,21,21^FD^FS";
      printstr = printstr + "^FO350,30^AXN,21,21^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^FO600,40^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO600,220^A0N,21,21^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO600,240^A0N,21,21^FD" + printbarCode[i + 2].substring(13) + "^FS";
      printstr = printstr + "^FO600,30^AXN,21,21^FD^FS";
      printstr = printstr + "^FO600,30^AXN,21,21^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

export function callPrint6(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print6(barCode, brandname, spec, color, retailprice, person);
}

export function Print6(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,30^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,260^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO350,40^AXN,21,21^FD" + "BRAND:" + printbrandname[i + 0] + "^FS";
    printstr = printstr + "^FO350,120^AXN,21,21^FD" + "TYPE:" + printspec[i + 0] + "^FS";
    var printctype = "色号:";
    if (printbarCode[i + 0].substring(0, 1).trim() == "8") {
      printctype = "球镜:";
    }
    printstr = printstr + "^FO350,160^AXN,21,21^FD" + printctype + printcolor[i + 0] + "^FS";
    printstr = printstr + "^FO350,200^AXN,35,35^FD" + "PRICE:" + printretailprice[i + 0] + "^FS";
    printstr = printstr + "^FO350,30^AXN,3,3^FD75^FS";
    printstr = printstr + "^FO370,30^AXN,3,3^FD45^FS";
    printstr = printstr + "^FO390,30^AXN,1,1^FD32^FS";
    printstr = printstr + "^FO350,30^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO370,30^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO390,30^AXN,1,1^FDnull^FS";
    printstr = printstr + "^PQ1^FS";
    printstr = printstr + "^XZ";
    i = i + 0;
  }
  return printstr
}

export function callPrint7(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return this.Print7(barCode, brandname, spec, color, retailprice, person);
}

export function Print7(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO180,40^AXR,70,70^FD^FS";
    printstr = printstr + "^FO180,40^AXR,70,70^FD^FS";
    printstr = printstr + "^PQ1^FS";
    printstr = printstr + "^XZ";
    i = i + 0;
  }
  return printstr
}

export function callPrint8(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print8(barCode, brandname, spec, color, retailprice, person);
}

export function Print8(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,30^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,240^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO100,110^AXN,3,3^FD^FS";
    printstr = printstr + "^FO350,150^AXN,3,3^FDhgdfh^FS";
    printstr = printstr + "^FO350,190^AXN,3,3^FDxbvc^FS";
    printstr = printstr + "^FO100,110^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO350,150^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO350,190^AXN,3,3^FDnull^FS";
    printstr = printstr + "^PQ1^FS";
    printstr = printstr + "^XZ";
    i = i + 0;
  }
  return printstr
}

export function callPrint9(barCodes, brandnames, specs, colors, retailprices, persons) {
  var barCode = '';
  var brandname = '';
  var spec = '';
  var color = '';
  var retailprice = '';
  var person = '';
  for (var cStr = 0; cStr < barCodes.length; cStr++) {
    barCode = barCode + barCodes[cStr] + '|';
    brandname = brandname + brandnames[cStr] + '|';
    spec = spec + specs[cStr] + '|';
    color = color + colors[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    person = person + persons[cStr] + '|';
  }
  return Print9(barCode, brandname, spec, color, retailprice, person);
}

export function Print9(barCode, brandname, spec, color, retailprice, person) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printbrandname = new Array();
  printbrandname = brandname.split('|');
  var printspec = new Array();
  printspec = spec.split('|');
  var printcolor = new Array();
  printcolor = color.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printperson = new Array();
  printperson = person.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0";
    printstr = printstr + "^FO100,40^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,220^A0N,21,21^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,240^A0N,21,21^FD" + printbarCode[i + 0].substring(13) + "^FS";
    printstr = printstr + "^FO100,40^AXN,3,3^FDerqwe^FS";
    printstr = printstr + "^FO130,40^AXN,3,3^FDadas^FS";
    printstr = printstr + "^FO160,40^AXN,3,3^FDcvzv^FS";
    printstr = printstr + "^FO190,40^AXN,1,1^FDuyit^FS";
    printstr = printstr + "^FO220,40^AXN,1,1^FDjkg^FS";
    printstr = printstr + "^FO100,40^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO130,40^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO160,40^AXN,3,3^FDnull^FS";
    printstr = printstr + "^FO190,40^AXN,1,1^FDnull^FS";
    printstr = printstr + "^FO220,40^AXN,1,1^FDnull^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^FO350,40^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO350,220^A0N,21,21^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO350,240^A0N,21,21^FD" + printbarCode[i + 1].substring(13) + "^FS";
      printstr = printstr + "^FO350,40^AXN,3,3^FDerqwe^FS";
      printstr = printstr + "^FO380,40^AXN,3,3^FDadas^FS";
      printstr = printstr + "^FO410,40^AXN,3,3^FDcvzv^FS";
      printstr = printstr + "^FO440,40^AXN,1,1^FDuyit^FS";
      printstr = printstr + "^FO470,40^AXN,1,1^FDjkg^FS";
      printstr = printstr + "^FO350,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO380,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO410,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO440,40^AXN,1,1^FDnull^FS";
      printstr = printstr + "^FO470,40^AXN,1,1^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^FO600,40^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO600,220^A0N,21,21^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO600,240^A0N,21,21^FD" + printbarCode[i + 2].substring(13) + "^FS";
      printstr = printstr + "^FO600,40^AXN,3,3^FDerqwe^FS";
      printstr = printstr + "^FO630,40^AXN,3,3^FDadas^FS";
      printstr = printstr + "^FO660,40^AXN,3,3^FDcvzv^FS";
      printstr = printstr + "^FO690,40^AXN,1,1^FDuyit^FS";
      printstr = printstr + "^FO720,40^AXN,1,1^FDjkg^FS";
      printstr = printstr + "^FO600,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO630,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO660,40^AXN,3,3^FDnull^FS";
      printstr = printstr + "^FO690,40^AXN,1,1^FDnull^FS";
      printstr = printstr + "^FO720,40^AXN,1,1^FDnull^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

export function PrintBand(that) {
  var barCode = new Array();
  var brandName = new Array();
  var quantity = new Array();
  var retailprice = new Array();
  for (var i = 0; i < that.dataList.length; i++) {
    barCode[barCode.length] = that.dataList[i].brandBarcode;
    brandName[brandName.length] = that.dataList[i].name;
    quantity[quantity.length] = that.dataList[i].quantity;
    retailprice[retailprice.length] = '';
  }
  printBarCodeForBrand(that,barCode, quantity, retailprice, brandName);
}

export function printBarCodeForBrand(that,barCode, quantity, retailprice, brandName) {
  var printCode = new Array();
  var retailprices = new Array();
  var brandNames = new Array();
  for (var i = 0; i < barCode.length; i++) {
    for (var a = 0; a < quantity[i]; a++) {
      printCode[printCode.length] = barCode[i];
      retailprices[retailprices.length] = retailprice[i];
      brandNames[brandNames.length] = brandName[i];
    }
  }
  let content = ''
  content = callPrintForBrand(printCode, retailprices, brandNames);
  that.axios({
    method: 'POST',
    url: 'http://noble-print:11881/noble-print/print/printContent',
    data: {
      content: content
    }
  }).then(response => {
    console.log(response)
  }).catch(function(error) {
    console.log(error);
  });
}

export function callPrintForBrand(printBarcode, retailprices, brandNames) {
  var str = '';
  var retailprice = '';
  var brandName = '';
  for (var cStr = 0; cStr < printBarcode.length; cStr++) {
    str = str + printBarcode[cStr] + '|';
    retailprice = retailprice + retailprices[cStr] + '|';
    brandName = brandName + brandNames[cStr] + '|';
  }
  return Print10(str, retailprice, 0, brandName);
}

export function Print10(barCode, retailprice, flag, brandName) {
  var printbarCode = new Array();
  printbarCode = barCode.split('|');
  var printretailprice = new Array();
  printretailprice = retailprice.split('|');
  var printbrandName = new Array();
  printbrandName = brandName.split('|');
  var num = 1;
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < printbarCode.length - 1; i++) {
    printstr = printstr + "^XA^LH10,10";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^AI26";
    printstr = printstr + "^BY2,2.0,10^LH0,0^FO100,20^BQN,6,6^FDQM,A" + printbarCode[i + 0] + "^FS";
    printstr = printstr + "^FO100,200^AX,25,25^FD" + printbarCode[i + 0].substring(0, 13) + "^FS";
    printstr = printstr + "^FO100,220^AXN,25,25^FD" + printbrandName[i + 0].substring(0, 9) + "^FS";
    printstr = printstr + "^PQ1^FS";
    if (printbarCode[i + 1]) {
      printstr = printstr + "^BY2,2.0,10^LH0,0^FO350,20^BQN,6,6^FDQM,A" + printbarCode[i + 1] + "^FS";
      printstr = printstr + "^FO350,200^AX,25,25^FD" + printbarCode[i + 1].substring(0, 13) + "^FS";
      printstr = printstr + "^FO350,220^AXN,25,25^FD" + printbrandName[i + 1].substring(0, 9) + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    if (printbarCode[i + 2]) {
      printstr = printstr + "^BY2,2.0,10^LH0,0^FO600,20^BQN,6,6^FDQM,A" + printbarCode[i + 2] + "^FS";
      printstr = printstr + "^FO600,200^AX,25,25^FD" + printbarCode[i + 2].substring(0, 13) + "^FS";
      printstr = printstr + "^FO600,220^AXN,25,25^FD" + printbrandName[i + 2].substring(0, 9) + "^FS";
      printstr = printstr + "^PQ1^FS";
    }
    printstr = printstr + "^XZ";
    i = i + 2;
  }
  return printstr
}

// 价签打印
export function printTag(that){
  for (var i = 0; i < that.dataList.length; i++) {
    let content = PrintJQ(that.dataList[i].brandBarcode, that.dataList[i].quantity);
    that.axios({
      method: 'POST',
      url: 'http://noble-print:11881/noble-print/print/printContent',
      data: {
        content: content
      }
    }).then(response => {
      console.log(response)
    }).catch(function(error) {
      console.log(error);
    });

  }
}

export function PrintJQ(text,num){
  var printstr = "";
  printstr = printstr + "\x1B\x40";
  for (var i = 0; i < num; i++) {
    printstr = printstr + "^XA^LH10,10";
    printstr = printstr + "^MD21";
    printstr = printstr + "^CWX,E:MSUNG24.FNT^FS";
    printstr = printstr + "^BY2,2.0,10^LH0,0^AI26";
    printstr = printstr + "^FO100,110^AXN,10,10^FH\^FDRMB:^FS";
    printstr = printstr + "^FO150,110^AXN,10,10^FH\^FD"+text+"^FS";
    printstr = printstr + "^PQ1,0,1,Y^XZ";
  }
  return printstr
}

/* * * * * * * * * 商品标价签打印 * * * * * * * * */
export function printGoodsTag(that){
  let brandList = new Array()
  let supplyList = new Array()
  let unitTypeList = new Array()
  let priceList = new Array()
  let maxPriceList = new Array()

  for(let i = 0; i < that.dataList.length; i++){
    brandList[brandList.length] = that.dataList[i].id
    supplyList[supplyList.length] = that.dataList[i].supplyId
    unitTypeList[unitTypeList.length] = that.dataList[i].unitType
    priceList[priceList.length] = that.dataList[i].minPrice + '/' + that.dataList[i].maxPrice
  }

  let brandStr = brandList.join(',')
  let supplyStr = supplyList.join(',')
  let unitTypeStr = unitTypeList.join(',')
  let priceStr = priceList.join(',')

  let sqlstr = "";

  for(var i=0; i<that.dataList.length; i++){
    sqlstr = sqlstr +'select \'' +that.dataList[i].name  +'\'brandName,\''+that.dataList[i].supplyName
        +'\'bspsuppliername,\''+that.dataList[i].unitType  +'\'bdunitname,\''+that.dataList[i].minPrice +'/'+ that.dataList[i].maxPrice +'\' as price';
    if(i != that.dataList.length - 1){
      sqlstr = sqlstr + ' union all ';
    }
  }

  return sqlstr
}
